import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.logging.Logger;

import javax.sql.DataSource;

public class MySqlDataSourceCommon implements DataSource
{
    private static final String MYSQL_DRIVER = "com.mysql.jdbc.Driver";

    static
    {
        try
        {
            Class.forName( MYSQL_DRIVER );
        }
        catch ( ClassNotFoundException e )
        {
            e.printStackTrace();
        }
    }
    private String ip;
    private String port;
    private String dbName;
    private String un;
    private String pw;

    public MySqlDataSourceCommon( String ip, String port, String dbName, String un, String pw )
    {
        this.ip = ip;

        this.port = port;

        this.dbName = dbName;

        this.un = un;

        this.pw = pw;
    }

    public Connection getConnection() throws SQLException
    {

        Connection cp = null;
        try
        {
            String url = "jdbc:mysql://" + ip + ":" + port + "/" + dbName + "?user=" + un
                + "&password=" + pw;

            cp = DriverManager.getConnection( url );

            return cp;
        }
        catch ( Exception e )
        {

            throw new SQLException( e.toString() );
        }
    }

    public Connection getConnection( String username, String password ) throws SQLException
    {
        throw new UnsupportedOperationException(
            "getConnection( String username, String password )" );
    }

    public PrintWriter getLogWriter() throws SQLException
    {
        throw new UnsupportedOperationException( "getLogWriter" );
    }

    public int getLoginTimeout() throws SQLException
    {
        throw new UnsupportedOperationException( "setLogWriter" );
    }

    public void setLogWriter( PrintWriter out ) throws SQLException
    {
        throw new UnsupportedOperationException( "setLogWriter" );

    }

    public void setLoginTimeout( int seconds ) throws SQLException
    {
        throw new UnsupportedOperationException( "setLogWriter" );

    }

    public boolean isWrapperFor( Class<?> arg0 ) throws SQLException
    {

        return false;
    }

    public Logger getParentLogger() throws SQLFeatureNotSupportedException
    {

        return null;
    }

    public <T> T unwrap( Class<T> iface ) throws SQLException
    {

        return null;
    }

}
